<template>
    <div id="templateDiv">
        <Spin size="large" fix v-if="ExportLoading"></Spin>
        <Form :label-width="170" inline>
            <Form-item label="发放年月:">
                <DatePicker type="month" v-model="queryParam.ssfa0002" :clearable="true"
                            placeholder="请选择发放年月" style="width: 200px" format="yyyy-MM"
                            @on-change="changeSsfa0002"  :editable="false"></DatePicker>
            </Form-item>
            <Form-item label="属地区划:">
                <area-linkage2 :areaCode.sync="queryParam.azaa0001" :time="ssfa0002" v-if="showArea"/>
            </Form-item>
            <Form-item label="姓名:">
                <Input v-model="queryParam.name" placeholder="请输入户主或成员姓名" style="width:200px"/>
            </Form-item>

            <Form-item label="身份证号码:">
                <Input v-model="queryParam.idCard" placeholder="请输入户主或成员身份证号码" style="width:200px"/>
            </Form-item>
            <Form-item label="救助类型:" v-if="type=='100100'||type=='200100'">
                <c-dict-select v-model="queryParam.assistanceType" dictCode="assistancetype" showKeys="100,101,102"
                               placeholder="请选择救助类型" v-if="type=='100100'"/>
                <c-dict-select v-model="queryParam.assistanceType" dictCode="assistancetype" showKeys="200,201,202,203"
                               placeholder="请选择救助类型" v-if="type=='200100'"/>
            </Form-item>
            <Form-item label="查询方式:">
                <Select v-model="queryParam.isMember" style="width: 200px" @on-change="changeIsMember">
                    <Option value="0">按户</Option>
                    <Option value="1">按人</Option>
                </Select>
            </Form-item>
            <span v-if="show">
                <Form-item label="家庭编号:">
                    <Input v-model="queryParam.azdf0001" placeholder="请输入家庭编号" style="width:200px"/>
                </Form-item>

                <Form-item label="低保证号:">
                    <Input v-model="queryParam.ssca0014" placeholder="请输入低保证号" style="width:200px"/>
                </Form-item>

                <Form-item label="受理编号:">
                    <Input v-model="queryParam.ssca0061" placeholder="请输入受理编号" style="width:200px"/>
                </Form-item>

                <Form-item label="批准时间:">
                    <DatePicker type="daterange" split-panels v-model="ssca0006_time"
                                placeholder="请选择批准时间" style="width: 200px"  :editable="false"></DatePicker>
                </Form-item>
                <Form-item label="联系人类型:" v-if="queryParam.isMember=='0'">
                    <c-dict-select v-model="queryParam.azdf0510" dictCode="contact_type"
                                   placeholder="请选择联系人类型"/>
                </Form-item>
                <Form-item label="联系人姓名:" v-if="queryParam.isMember=='0'">
                    <Input v-model="queryParam.azdf0511" placeholder="请输入联系人姓名" style="width:200px"/>
                </Form-item>
                <Form-item label="联系人电话:" v-if="queryParam.isMember=='0'">
                    <Input v-model="queryParam.azdf0011" placeholder="请输入联系人电话" style="width:200px"/>
                </Form-item>

                <Form-item label="致贫原因:" v-if="queryParam.isMember!='1'">
                    <c-dict-select v-model="queryParam.ssca0013" dictCode="poorreason"
                                   placeholder="请选择致贫原因"/>
                </Form-item>

                <Form-item label="性别:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0004" dictCode="sex" placeholder="请选择性别"/>
                </Form-item>

                <Form-item label="民族:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0007" dictCode="nation"
                                   placeholder="请选择民族"/>
                </Form-item>

                <Form-item label="健康状况:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0009" dictCode="health"
                                   placeholder="请选择健康状况"/>
                </Form-item>

                 <Form-item label="是否残疾:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0503" dictCode="yesorno"
                                   placeholder="请选择是否残疾"/>
                </Form-item>

                <Form-item label="残疾类别:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0504" dictCode="disabilitytype"
                                   placeholder="请选择残疾类别"/>
                </Form-item>
                <Form-item label="残疾等级:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0505" dictCode="disabilityclass"
                                   placeholder="请选择残疾等级"/>
                </Form-item>
                <Form-item label="单人保类型:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0583" dictCode="alonetype"
                                   placeholder="请选择单人保类型" :disabled="azcp0583Disabled"/>
                </Form-item>

                 <Form-item label="建档立卡类型:" v-if="queryParam.isMember=='1'&&type=='200100'">
                    <c-dict-select v-model="queryParam.azcp0584" dictCode="filing_type"
                                   placeholder="请选择建档立卡类型" :disabled="azcp0584Disabled"/>
                </Form-item>
                <Form-item label="劳动能力丧失情况:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0502" dictCode="workability"
                                   placeholder="请选择劳动能力丧失情况"/>
                </Form-item>
                <Form-item label="是否享受失能半失能补贴:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.azcp0555" dictCode="loseability"
                                   placeholder="请选择是否享受失能半失能补贴"/>
                </Form-item>
                 <Form-item label="分类救助上浮类别:" v-if="queryParam.isMember=='1'">
                    <c-dict-select v-model="queryParam.ssbi0004" dictCode="classifyaidstandard"
                                   placeholder="请选择分类救助上浮类别" :width="400"/>
                </Form-item>
                <Form-item label="身份类别:" v-if="queryParam.isMember=='1'">
                  <Select v-model="queryParam.sflb" style="width: 200px" clearable>
                    <Option value='01'> 在职人员 </Option>
					<Option value='03'> 登记失业人员 </Option>
					<Option value='06'> 未登记失业人员 </Option>
					<Option value='04'> 无就业条件人员 </Option>
					<Option value='05'> 离退休人员 </Option>
					<Option value='02'> 灵活就业人员 </Option>
                    <Option value='07'> 其他 </Option>
					<Option value='11'> 学生 </Option>
					<Option value='12'> 学龄前儿童 </Option>
                </Select>
                </Form-item>

                <Form-item label="救助金额:">
                    <InputNumber v-model="queryParam.money_begin" :min="0" placeholder="" style="width:93px"/>
                    ~
                    <InputNumber v-model="queryParam.money_end" :min="0" placeholder="" style="width:93px"/>
                </Form-item>

                <Form-item label="年龄:" v-if="queryParam.isMember=='1'">
                    <InputNumber v-model="queryParam.age_begin" :min="0" placeholder="" style="width:93px"/>
                    ~
                    <InputNumber v-model="queryParam.age_end" :min="0" placeholder="" style="width:93px"/>
                </Form-item>


            </span>
            <div style="display: inline-block;cursor:pointer" @click="showHidden">
                <template v-if="show">
                    <Form-item label="收起条件" style="cursor:pointer">
                        <div class="ivu-form-item">
                        <span class="ivu-input-suffix">
                          <Icon type="ios-arrow-up"/>
                        </span>
                        </div>
                    </Form-item>
                </template>
                <template v-else>
                    <Form-item label="展开条件" style="cursor:pointer">
                        <div class="ivu-form-item">
                        <span class="ivu-input-suffix">
                            <Icon type="ios-arrow-down"/>
                        </span>
                        </div>
                    </Form-item>
                </template>
            </div>
            <Row class="button_row">
                 <span style="float: left;">
                 <Button type="primary" @click="exportExcelFamily" v-if="queryParam.isMember=='0'">{{buttonName}}花名册导出(户)</Button>
                 <Button type="primary"
                         @click="exportExcelMember" v-else>{{buttonName}}花名册导出(人)</Button>
                </span>
                <span style="float: right;">
                 <Button type="primary"  @click="searchQueryNew">查询</Button>
                 <Button type="primary" class="button_item_left" @click="searchResetNew">重置</Button>
                     </span>
            </Row>
        </Form>

        <div id="statistics">
            <span>查询统计:</span>
            <span>{{typeName}}总户数 [ {{statistics.familyNum}} ] 户</span>
            <span>保障人口总数 [ {{statistics.memberNum}} ] 人</span>
            <span>总高龄补贴金额 [ {{statistics.sumSsbi0008}} ] 元</span>
            <span v-if="type!='100200'&&type!='200200'">总救助金额 [ {{statistics.helpmoney}} ] 元</span>
            <span v-if="type!='100200'&&type!='200200'">总金额 [ {{statistics.money}} ] 元</span>
        </div>

        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       highlight-hover-row
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :data="tableData">
                <vxe-table-column field="assistanceType" title="救助类型" align="center" width="200" fixed="left"/>
                <vxe-table-column field="azaa0002" title="属地区划" align="center" width="220" fixed="left"/>
                <vxe-table-column field="azcp0003" title="户主姓名" align="center" width="100" fixed="left"/>
                <template v-if="queryParam.isMember=='0'">
                    <vxe-table-column field="azcp0001" title="户主身份证号码" align="center" width="200" fixed="left" key="4"/>
                    <vxe-table-column field="ssfa0002" title="发放年月" align="center" width="100" :formatter="renderTime1"
                                      key="5"/>
                    <vxe-table-column field="azdf0001" title="家庭编号" align="center" width="180" key="6"/>
                    <vxe-table-column field="ssca0014" title="低保证号" align="center" width="140" key="7"/>
                    <vxe-table-column field="ssca0011" title="银行账号" align="center" width="140" key="8"/>
                    <vxe-table-column field="ssca0049" title="家庭月总收入" align="center" width="200" key="9"/>
                    <vxe-table-column field="ssca0051" title="家庭人口数" align="center" width="100" key="10"/>
                    <vxe-table-column field="ssca0052" title="保障人口数" align="center" width="100" key="11"/>
                    <vxe-table-column field="azdf0008" title="家庭住址" align="center" width="200" key="12"/>
                    <vxe-table-column field="ssca0025" title="分类救助上浮总金额" align="center" width="160" key="13"/>
                    <vxe-table-column field="ssca0065" title="家庭高龄补贴总金额" align="center" width="160" key="14"/>
                    <vxe-table-column field="ssca0026" title="救助金额" align="center" width="140" key="15"/>
                    <vxe-table-column field="familyFullMoney" title="总金额" align="center" width="140" key="16"/>
                    <vxe-table-column field="ssca0006" title="批准时间" align="center" width="140" :formatter="renderTime"
                                      key="99"/>
                </template>
                <template v-if="queryParam.isMember=='1'">
                    <vxe-table-column field="userAzcp0003" title="成员姓名" align="center" width="140" key="17"/>
                    <vxe-table-column field="userAzcp0001" title="成员证件号码" align="center" width="180" key="18"/>
                    <vxe-table-column field="age" title="年龄" align="center" width="100" key="19"/>
                    <vxe-table-column field="ssfa0002" title="发放年月" align="center" width="100" key="20"
                                      :formatter="renderTime1"/>
                    <vxe-table-column field="azdf0001" title="家庭编号" align="center" width="180" key="21"/>
                    <vxe-table-column field="ssca0014" title="低保证号" align="center" width="140" key="22"/>
                    <vxe-table-column field="azdf0008" title="家庭住址" align="center" width="200" key="23"/>
                    <vxe-table-column field="ssbi0004" title="分类救助上浮类别" align="center" width="140" key="24"/>
                    <vxe-table-column field="ssbi0005" title="分类救助上浮金额" align="center" width="140" key="25"/>
                    <vxe-table-column field="ssbi0008" title="高龄补贴金额" align="center" width="140" key="26"/>
                    <vxe-table-column field="azcp0548" title="救助金额" align="center" width="140" key="27"/>
                    <vxe-table-column field="fullMoney" title="总金额" align="center" width="140" key="28"/>
                    <vxe-table-column field="ssca0006" title="批准时间" align="center" width="140" :formatter="renderTime"
                                      key="29"/>
                    <vxe-table-column field="azcp0517" title="与申请人关系" align="center" width="140" key="30"/>
                    <vxe-table-column field="azcp0004" title="性别" align="center" width="140" key="31"/>
                    <vxe-table-column field="azcp0013" title="户籍类别" align="center" width="140" key="32"/>
                    <vxe-table-column field="azcp0007" title="民族" align="center" width="140" key="33"/>
                    <vxe-table-column field="azcp0008" title="文化程度" align="center" width="140" key="34"/>
                    <vxe-table-column field="azcp0009" title="健康状况" align="center" width="140" key="35"/>
                    <vxe-table-column field="azcp0505" title="残疾等级" align="center" width="140" key="36"/>
                    <vxe-table-column field="azcp0504" title="残疾类别" align="center" width="140" key="37"/>
                    <vxe-table-column field="azcp0502" title="劳动能力丧失情况" align="center" width="140" key="38"/>
                </template>
                <!--<vxe-table-column field="ssca0013" title="致贫原因" align="center" width="140"/>-->
                <!--<vxe-table-column field="ssca0032" title="数据来源" align="center" width="140" :formatter="renderSsca0032"/>-->
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {getAction, postAction} from '@/api/request'
    import AreaLinkage2 from './AreaLinkage'

    export default {
        name: "list",
        mixins: [CommonMixin],
        components: {
            AreaLinkage2
        },
        data() {
            return {
                ssca0006_time:[],
                queryParam: {
                    isMember: "0",
                    money_begin: null,
                    money_end: null,
                    age_begin: null,
                    age_end: null,
                },
                azcp0583Disabled: true,
                azcp0584Disabled: true,
                type: "",
                typeName: "",
                buttonName: "",
                ExportLoading: false,
                statistics: {
                    familyNum: 0,
                    memberNum: 0,
                    sumSsbi0008: 0,
                    helpmoney: 0.00,
                    money: 0.00
                },
                ssfa0002: "",
                Loading: false,
                show: false,
                url: {
                    list: "/api/ac/subsistence/reliefRosterServiceImpl/list",
                    exportExcel: "/api/ac/subsistence/reliefRosterServiceImpl/exportExcel",
                },
                exportFileName: "",
                showArea: false,
            }
        },
        watch: {
            'queryParam.assistanceType': function (e) {
                this.azcp0583Disabled = true;
                this.azcp0584Disabled = true;
                this.$set(this.queryParam, "azcp0583", null);
                this.$set(this.queryParam, "azcp0584", null);
                if (e == "101" || e == "201") {
                    this.azcp0583Disabled = false;
                } else if (e == "203") {
                    this.azcp0584Disabled = false;
                }
            },
        },
        methods: {
            changeSsfa0002() {
                this.setTime();
                this.ssfa0002 = this.queryParam.ssfa0002;
                this.queryParam.azaa0001 = "";
            },
            renderTime1(h) {
                if (h.cellValue) {
                    return this.DateFormat(h.cellValue, 'YYYY-MM');
                }
            },
            searchQueryNew() {
                this.setTime();
                this.loadData(1);
            },
            exportExcelFamily() {
                if (this.checkSsfa0002()) {
                    this.queryParam.member = '0';
                    this.setTime();
                    this.changeExportFileName();
                    this.exportExcel();

                }
            },
            exportExcelMember() {
                if (this.checkSsfa0002()) {
                    this.queryParam.member = '1';
                    this.setTime();
                    this.changeExportFileName();
                    this.exportExcel();
                }
            },
            //判断发放年月是否为空
            checkSsfa0002() {
                if (!this.queryParam.ssfa0002) {
                    this.$Message.error("请选择发放年月！");
                    return false
                } else {
                    return true
                }
            },
            changeExportFileName() {
                var ssfa0002 = this.queryParam.ssfa0002;
                var assistanceType = this.queryParam.assistanceType
                if (assistanceType) {
                    if (assistanceType == "100") {
                        this.exportFileName = "城市最低生活保障救助对象花名册" + ssfa0002;
                    } else if (assistanceType == "101") {
                        this.exportFileName = "城市单人保救助对象花名册" + ssfa0002;
                    } else if (assistanceType == "102") {
                        this.exportFileName = "城市因病致贫救助对象花名册" + ssfa0002;
                    } else if (assistanceType == "200") {
                        this.exportFileName = "农村最低生活保障救助对象花名册" + ssfa0002;
                    } else if (assistanceType == "201") {
                        this.exportFileName = "农村单人保救助对象花名册" + ssfa0002;
                    } else if (assistanceType == "202") {
                        this.exportFileName = "农村因病致贫救助对象花名册" + ssfa0002;
                    } else if (assistanceType == "203") {
                        this.exportFileName = "农村建档立卡救助对象花名册" + ssfa0002;
                    }
                } else {
                    var type = this.type;
                    if (type == "100100") {
                        this.exportFileName = "城市救助对象花名册" + ssfa0002;
                    } else if (type == "200100") {
                        this.exportFileName = "农村救助对象花名册" + ssfa0002;
                    } else if (type == "100200") {
                        this.exportFileName = "城市低保边缘家庭花名册" + ssfa0002;
                    } else if (type == "200200") {
                        this.exportFileName = "农村低保边缘家庭花名册" + ssfa0002;
                    }
                }
            },
            setTime() {
                var time = this.ssca0006_time;
                if (time) {
                    if (time[0]) {
                        this.queryParam.ssca0006_begin = this.DateFormat(time[0], 'YYYY-MM-DD') + " 00:00:00";
                    }else{
                        this.queryParam.ssca0006_begin =null;
                    }
                    if (time[1]) {
                        this.queryParam.ssca0006_end = this.DateFormat(time[1], 'YYYY-MM-DD') + " 23:59:59";
                    }else{
                        this.queryParam.ssca0006_end = null;
                    }
                }
                var ssfa0002 = this.queryParam.ssfa0002;
                if (!ssfa0002) {
                    this.queryParam.ssfa0002 = null;
                } else {
                    this.queryParam.ssfa0002 = this.DateFormat(ssfa0002, 'YYYY-MM');
                }
            },
            showHidden() {
                this.show = !this.show;
            },
            changeIsMember(v) {
                var ssca0002 = this.queryParam.ssfa0002;
                var azaa0001 = this.queryParam.azaa0001;
                //this.show = false;
                this.queryParam = {
                    isMember: v,
                    money_begin: null,
                    money_end: null,
                    age_begin: null,
                    age_end: null,

                }
                this.queryParam.azaa0001 = azaa0001;
                this.queryParam.type = this.type;
                this.queryParam.ssfa0002 = this.DateFormat(ssca0002, 'YYYY-MM');
                this.resetTable();
            },
            searchResetNew() {
                this.queryParam = {
                    isMember: "0",
                    money_begin: null,
                    money_end: null,
                    age_begin: null,
                    age_end: null
                }
                this.queryParam.type = this.type;
                this.queryParam.ssfa0002 = this.DateFormat(new Date(), 'YYYY-MM');
                this.resetTable();
            },
            loadData(arg) {
                if (arg == 1) {
                    this.pageNo = 1;
                }
                let that = this;
                that.Loading = true;
                let param = Object.assign({}, this.queryParam);
                let url = this.url.list;
                param.pageNo = this.pageNo;
                param.pageSize = this.pageSize;
                postAction(url, param).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.tableData = res.data.data.pageList.results;
                        that.dataCount = res.data.data.pageList.totalRecord;
                        that.statistics = res.data.data.statistics;
                    }
                }).finally(() => {
                    that.Loading = false;
                })
            },
            edit(type, typeName, buttonName) {
                this.queryParam.type = type;
                this.type = type;
                this.typeName = typeName;
                this.buttonName = buttonName;
                this.queryParam.ssfa0002 = this.DateFormat(new Date(), 'YYYY-MM');
                this.ssfa0002 = this.DateFormat(new Date(), 'YYYY-MM');
                this.showArea = true;
                //this.loadData(1);
            },
            resetTable() {
                this.tableData = [];
                this.dataCount = 0;
                this.statistics = {
                    "money": 0.00,
                    "familyNum": 0,
                    "helpmoney": 0.00,
                    "memberNum": 0,
                    "sumSsbi0008": 0.0,
                };
            }
        },

        // created() {
        //     this.loadData();
        // }
        // ,
    }
</script>

<style scoped>


    /deep/ .ivu-upload-list {
        display: none;
    }

    /deep/ .ivu-table-cell {
        padding-right: 0px;
        padding-left: 0px;
    }

    /deep/ .ivu-form-item {
        margin-bottom: 10px;
    }

    #statistics {
        height: 50px;
        line-height: 50px;
        width: 100%;
        color: red;
        font-size: 16px;
    }

    #statistics span {
        padding-left: 10px;
        padding-right: 10px;
    }

</style>
